#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

#define flr(x,l,r) for (int x = l; x <= r; ++ x)
#define frl(x,r,l) for (int x = r; x >= l; -- x)
#define LL long long 
#define szf sizeof
#define in(x) scanf("%d", &x)
#define out(x) printf("%d", x)
#define pn printf("\n")
#define con continue
#define bk break
#define vc vector 
#define pb push_back
#define sz size

using namespace std;

const int N = 3e5 + 10;

int n, m;
int s[N], q[N];

int main() {
	in(n), in(m);
	
	flr (i, 1, n) in(s[i]), s[i] += s[i - 1];
	
	int res = -1e9, hh = 0, tt = 0;
	flr (i, 1, n) {
	    if (q[hh] < i - m) hh ++ ;
	    res = max(res, s[i] - s[q[hh]]);
	    while (hh <= tt && s[q[tt]] >= s[i]) tt -- ;
	    q[ ++ tt] = i;
	}
	
	out(res), pn;
	
	return 0;
}